package Oct_2020.part6;

import java.util.Objects;

public class Per {
    public static void main(String[] args) {
        person p=new person();
        System.out.println(p);
    }
}
class person{
//    构造方法
// alt+insert 快速构造构造函数

    public person() {
    }

    public person(String name, int age) {
        this.name = name;
        this.age = age;
    }

    String name;
    int age;

    /**
     * @return
     */
    @Override
    public String toString() {
        return "person{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    @Override
    public boolean equals(Object o) {
//        自己等于自己，当然相等
        if (o == this) return true;
//        为空或者类别不同时返回FALSE
        if (o == null || getClass() != o.getClass()) return false;
        person person = (person) o;
        return age == person.age &&
                Objects.equals(name, person.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, age);
    }
}
